Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.DirectoryServices
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Transactions
Public Class BLL_GroupCotrol
    Public Sub UpdateData(ByVal GroupName As String, ByVal VOrganizationID As Integer, ByVal GroupID As Integer)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat("Update GroupVOrganizationMapping Set ")
        sql.AppendFormat("GroupName='{0}' ", GroupName)
        sql.AppendFormat("Where VOrganizationID ={0} ", VOrganizationID)
        sql.AppendFormat("AND GroupID={0} ", GroupID)
        dat.AccData(sql)

    End Sub

    Public Sub InsertData(ByVal GroupName As String, ByVal VOrganizationID As Integer)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat("Insert Into GroupVOrganizationMapping (GroupName,VOrganizationID) ")
        sql.AppendFormat("Select ")
        sql.AppendFormat("'{0}' ", GroupName)
        sql.AppendFormat(",{0} ", VOrganizationID)

        dat.AccData(sql)

    End Sub

    Public Sub DeleteData(ByVal VOrganizationID As Integer, ByVal GroupID As Integer)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.Length = 0
        sql.AppendFormat("Delete From GroupVOrganizationMapping ")
        sql.AppendFormat("Where VOrganizationID ={0} ", VOrganizationID)
        sql.AppendFormat("AND GroupID={0} ", GroupID)
        dat.AccData(sql)

    End Sub

    Public Function SelectData(ByVal VOrganizationID As Integer) As DataTable

        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        sql.Length = 0
        sql.AppendFormat("select distinct g.GroupID,vo.VOrganizationName,g.GroupName,case when v.GroupID <>'' then '0' else '1' end as IsDelete from GroupVOrganizationMapping  g ")
        sql.AppendFormat("left join GroupVolunteerMapping v on g.GroupID=v.GroupID ")
        sql.AppendFormat("left join VOrganizationViewV2 vo on g.VOrganizationID=vo.VOrganizationID ")
        sql.AppendFormat("where g.VOrganizationID={0} ", VOrganizationID)

        Return dat.GetData(sql)
    End Function
    Public Function GroupNameIsExist(ByVal VOrganizationID As Integer, ByVal GroupName As String) As Boolean
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        sql.Length = 0
        sql.AppendFormat("SELECT GroupName FROM GroupVOrganizationMapping ")
        sql.AppendFormat("Where VOrganizationID ={0} ", VOrganizationID)
        sql.AppendFormat("and GroupName='{0}' ", GroupName)
        If dat.GetData(sql).Rows.Count > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Function GetOriGroupName(ByVal VOrganizationID As Integer, ByVal GroupID As String) As String
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        sql.Length = 0
        sql.AppendFormat("SELECT GroupName FROM GroupVOrganizationMapping ")
        sql.AppendFormat("Where VOrganizationID ={0} ", VOrganizationID)
        sql.AppendFormat("and GroupID='{0}' ", GroupID)

        Return dat.GetSingleData(sql.ToString, Nothing, CommandType.Text)
    End Function
End Class
